subdir('app')
subdir('pd')
subdir('mlib')

dc = meson.get_compiler('d')

d_args = []
d_versions = []
link_args = []

if dc.get_id() == 'gcc'
  if dc.version().version_compare('<13.0.0') and dc.version().version_compare('>=12.0.0')
    # GDC 12 has a linking issue when linking separate object files. Not sure about newer versions.
    # https://forum.dlang.org/thread/lgthiiqufrrkjbpohtgq@forum.dlang.org
    d_args += '-fall-instantiations'
    message('GDC 12 detected -- using -fall-instantiations flag (slower compile speeds)')
  endif
endif

# Link with the CoreFoundation and ImageIO frameworks
if host_machine.system() == 'darwin'
  # NOTE: ldc2 isn't supported as mentioned in the README
  #       This might change once https://github.com/ldc-developers/ldc/pull/4777
  #       makes it into a release.
  #
  # No support for GDC because IDK how to get that to work on macOS.
  if dc.get_id() == 'dmd'
    link_args += '-Xcc=-framework'
    link_args += '-Xcc=CoreFoundation'
  endif
else
  if not get_option('with-gm-converter')
    d_versions += 'PD_NO_CONVERTER'
  endif
endif

executable(meson.project_name(),
  sources: app_files + pd_files,
  include_directories: include_directories('pd', 'mlib'),
  install: true,
  link_with: [libmlib],
  d_args: d_args,
  d_module_versions: d_versions,
  link_args: link_args,
  install_rpath: get_option('prefix') / get_option('libdir') / 'pd'
)

subdir('plugins')
